package com.ruoyi.web.controller.mbti;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MbtiQuestion;
import com.ruoyi.system.service.IMbtiQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * MBTI题目Controller
 * 
 * @author ruoyi
 * @date 2025-01-21
 */
@RestController
@RequestMapping("/mbti/question")
public class MbtiQuestionController extends BaseController
{
    @Autowired
    private IMbtiQuestionService mbtiQuestionService;

    /**
     * 查询MBTI题目列表
     */
    @PreAuthorize("@ss.hasPermi('mbti:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(MbtiQuestion mbtiQuestion)
    {
        startPage();
        List<MbtiQuestion> list = mbtiQuestionService.selectMbtiQuestionList(mbtiQuestion);
        return getDataTable(list);
    }

    /**
     * 导出MBTI题目列表
     */
    @PreAuthorize("@ss.hasPermi('mbti:question:export')")
    @Log(title = "MBTI题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MbtiQuestion mbtiQuestion)
    {
        List<MbtiQuestion> list = mbtiQuestionService.selectMbtiQuestionList(mbtiQuestion);
        ExcelUtil<MbtiQuestion> util = new ExcelUtil<MbtiQuestion>(MbtiQuestion.class);
        util.exportExcel(response, list, "MBTI题目数据");
    }

    /**
     * 获取MBTI题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('mbti:question:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return success(mbtiQuestionService.selectMbtiQuestionByQuestionId(questionId));
    }

    /**
     * 新增MBTI题目
     */
    @PreAuthorize("@ss.hasPermi('mbti:question:add')")
    @Log(title = "MBTI题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MbtiQuestion mbtiQuestion)
    {
        mbtiQuestion.setCreateBy(getUsername());
        return toAjax(mbtiQuestionService.insertMbtiQuestion(mbtiQuestion));
    }

    /**
     * 修改MBTI题目
     */
    @PreAuthorize("@ss.hasPermi('mbti:question:edit')")
    @Log(title = "MBTI题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MbtiQuestion mbtiQuestion)
    {
        mbtiQuestion.setUpdateBy(getUsername());
        return toAjax(mbtiQuestionService.updateMbtiQuestion(mbtiQuestion));
    }

    /**
     * 删除MBTI题目
     */
    @PreAuthorize("@ss.hasPermi('mbti:question:remove')")
    @Log(title = "MBTI题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(mbtiQuestionService.deleteMbtiQuestionByQuestionIds(questionIds));
    }

    /**
     * 根据测试类型ID查询题目列表（支持匿名访问）
     */
    @GetMapping("/listByTestType/{testTypeId}")
    public AjaxResult listByTestType(@PathVariable Long testTypeId)
    {
        List<MbtiQuestion> list = mbtiQuestionService.selectQuestionsByTestTypeId(testTypeId);
        return success(list);
    }
}
